package com.xian.im.modules.im.core.impl;

import com.xian.im.common.validator.ValidatorUtils;
import com.xian.im.common.validator.group.LoginGroup;
import com.xian.im.modules.im.controller.model.login.LoginReq;
import com.xian.im.modules.im.controller.model.login.OrgLoginReq;
import com.xian.im.modules.im.core.IOrganizationCoreService;
import com.xian.im.modules.im.core.LoginService;
import com.xian.im.modules.im.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: xian-code
 * @description:
 * @author: liru.xian
 * @create: 2021-01-21 19:21
 **/
@Slf4j
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private AccountService accountService;
    @Autowired
    private IOrganizationCoreService organizationCoreService;
    /**
     * @param loginReq
     * @return
     */
    @Override
    public Boolean login(LoginReq loginReq) {
        ValidatorUtils.validateEntity(loginReq, LoginGroup.class);
        if (accountService.checkLoginPermissions(loginReq)){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    /**
     * @param loginReq
     * @return
     */
    @Override
    public Boolean login(OrgLoginReq loginReq) {
        ValidatorUtils.validateEntity(loginReq, LoginGroup.class);
        if (organizationCoreService.checkLoginPermissions(loginReq)) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}
